package com.javafactroy.kunlong.test;

import cn.hutool.core.util.HexUtil;
import com.javafactroy.kunlong.FileServer;
import com.javafactroy.kunlong.batch.User;
import com.javafactroy.kunlong.liteflow.FlowRequest;
import com.javafactroy.kunlong.liteflow.LiteContext;
import com.javafactroy.kunlong.liteflow.YourFlow;
import com.yomahub.liteflow.flow.LiteflowResponse;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

// https://zhuanlan.zhihu.com/p/568512977
@SpringBootTest(classes = {FileServer.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ExtendWith(SpringExtension.class)
@Slf4j
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestLiteFlow {

    //https://blog.healerjean.com/springboot/2023/07/24/%E6%B5%81%E7%A8%8B%E7%BC%96%E6%8E%92%E4%B9%8BLiteFlow/
    @Autowired
    YourFlow yourFlow;

    @Data
    public static class MyCls<T> {
        T data;

        <R> R findData() {
            return (R) data;
        }

    }

    @Test
    public void test000() throws Exception {

        MyCls<User> myCls = new MyCls();
        myCls.setData(new User());
        User user = myCls.findData();

    }

    @Test
    public void test001_liteFlow() throws Exception {
        FlowRequest<User> request = new FlowRequest<>();
        request.setId(2023).setRemark("flow").setData(new User());
        request.getData().setId(1l).setAge(12).setName("song").setPkey(11l);
        LiteflowResponse resp = yourFlow.dxpFlow(request);
        LiteContext<User> context = resp.getContextBean(LiteContext.class);
        log.info("{}", context);
    }

    @Test
    public void test002_liteParell() throws Exception {

        yourFlow.parell();
    }

    @Test
    public void test003() {
        String hex = HexUtil.encodeHexStr("abcdefghijklmn".getBytes());
        log.info("hex={}", hex);
        String str = HexUtil.decodeHexStr(hex);

        log.info("str={}", str);
    }

}
